package com.weishi.project.training.controller;

import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.framework.web.page.TableDataInfo;
import com.weishi.project.training.domain.SportsmanBodyShape;
import com.weishi.project.training.service.ISportsmanBodyShapeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 身体形态 控制器
 */
@RestController
@RequestMapping("/training/sportsmanBodyShape")
public class SportsmanBodyShapeController extends BaseController {

    @Autowired
    private ISportsmanBodyShapeService sportsmanBodyShapeService;

    /**
     * 查询身体形态 列表
     */
    @PreAuthorize("@ss.hasPermi('training:shape:list')")
    @GetMapping("/list")
    public TableDataInfo list(SportsmanBodyShape sportsmanBodyShape) {
        startPage();
        List<SportsmanBodyShape> list = sportsmanBodyShapeService.selectSportsmanBodyShapeList(sportsmanBodyShape);
        return getDataTable(list);
    }

    /**
     * 导出身体形态 列表
     */
    @PreAuthorize("@ss.hasPermi('training:shape:export')")
    @Log(title = "身体形态 ", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SportsmanBodyShape sportsmanBodyShape) {
        List<SportsmanBodyShape> list = sportsmanBodyShapeService.selectSportsmanBodyShapeList(sportsmanBodyShape);
        ExcelUtil<SportsmanBodyShape> util = new ExcelUtil<SportsmanBodyShape>(SportsmanBodyShape.class);
        return util.exportExcel(list, "shape");
    }

    /**
     * 获取身体形态 详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:shape:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sportsmanBodyShapeService.getById(id));
    }

    /**
     * 新增身体形态 
     */
    @PreAuthorize("@ss.hasPermi('training:shape:add')")
    @Log(title = "身体形态 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SportsmanBodyShape sportsmanBodyShape) {
        sportsmanBodyShape.setCtime(new Date());
        sportsmanBodyShapeService.save(sportsmanBodyShape);
        return AjaxResult.success();
    }

    /**
     * 修改身体形态 
     */
    @PreAuthorize("@ss.hasPermi('training:shape:edit')")
    @Log(title = "身体形态 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SportsmanBodyShape sportsmanBodyShape) {
        sportsmanBodyShapeService.updateById(sportsmanBodyShape);
        return AjaxResult.success();
    }

    /**
     * 删除身体形态 
     */
    @PreAuthorize("@ss.hasPermi('training:shape:remove')")
    @Log(title = "身体形态 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        sportsmanBodyShapeService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }



    
}